import os
import logging

import views

from models import Payer
from models import Waiter
from models import Tshirt

def index(request):
  """ """
  params = {
    'show_dishola_broughtby': True
  }
  return views.respond(request, 'index', params)

def pages(request, page=''):
  """ """
  if page == 'thanks' or 'tshirt' or 'soldout' or 'waiting_list':
    footer = ''
  else :
    footer = '<cite>&copy;2009 Mick Vann</cite>'

  params = {
    'content_footer': footer,
    'show_dishola_broughtby': False
  }
  return views.respond(request, page, params)

def email(request, year):
  params = {}
  return views.respond(request, '%s_email' % year, params)

def thanks(request):
  """ """
  params = {
    'show_dishola_broughtby': True
  }
  return views.respond(request, 'thanks', params)

def tshirt(request):
  if request.method == 'POST':
    fullname = request.POST['fullname']
    ticketname = request.POST['ticketname']
    size = request.POST['size']
    tshirt = Tshirt(fullname=fullname, ticketname=ticketname, size=size)
    tshirt.put()
    params = {'fullname': fullname, 'size': size}
    return views.respond(request, 'tshirt', params)

def soldout(request):
  if request.method == 'GET':
    params = {}
    return views.respond(request, 'soldout', params)
  else:
    email = request.POST['email']
    if email != '':
      waiter = Waiter(email=email)
      waiter.put()
      params = {'email': email}
      return views.respond(request, 'waiting_list', params)


def paypal_ipn(request):
  if request.method == 'POST':
    first_name = request.POST['first_name']
    last_name = request.POST['last_name']
    email = request.POST['payer_email']
    payment_date = request.POST['payment_date']

    payer = Payer(first_name=first_name,
      last_name=last_name, email=email, payment_date=payment_date)
    payer.put()
